SHELL := /bin/bash

CC=g++

# ----------------------------------------

SDIR=src
IDIR=include
LDIR=lib
ODIR=obj

# ----------------------------------------

_OBJ = main printer translator
_EXEC = ftc

# ----------------------------------------

ifeq ($(mode),debug)
	CFLAGS=-I$(IDIR) -I$(CARLO)/include -std=gnu++0x -DDEBUG -Wall -O0 -g
else
	mode = release
	CFLAGS=-I$(IDIR) -I$(CARLO)/include -std=gnu++0x -DNDEBUG -Wall -O2
endif
    
LFLAGS=-L$(LDIR) -L$(CARLO)/lib -lrose

# ----------------------------------------

OBJ = $(patsubst %,$(ODIR)/%.o,$(_OBJ))

# ----------------------------------------

-include $(OBJ:.o=.o.d)

$(ODIR)/%.o: $(SDIR)/%.cpp
	$(CC) -c -o $@ $< $(CFLAGS)
	$(CC) -MM $< $(CFLAGS) > $@.d
	@mv -f $@.d $@.d.tmp
	@sed -e 's|.*:|$@:|' < $@.d.tmp > $@.d
	@sed -e 's/.*://' -e 's/\\$$//' < $@.d.tmp | fmt -1 | sed -e 's/^ *//' -e 's/$$/:/' >> $@.d
	@rm -f $@.d.tmp

all: $(OBJ)
	$(CC) -o $(_EXEC) $(OBJ) $(LFLAGS)
	@echo "............................"
	@echo "make complete!"
	@echo ""
	
# ----------------------------------------

.PHONY: clean

clean:
	rm -f $(ODIR)/*.o *~ core $(IDIR)/*~ 
	rm -f $(ODIR)/*.o.d *~ core $(IDIR)/*~ 

